<html>

<head>
	<title>Web activity manager - Aggiungi operatori </title>
	<link href="menu/menu.css" rel="stylesheet" type="text/css"/>
	<script src="xmlLoader.js" type="text/javascript"></script>
	<script src="menu_and_sessiondata.js" type="text/javascript"></script>
	<script type="text/javascript">
		
		function init(){
		
			loadSessionData();
			generateMenu();
			loadOperatori();
			generateFunctions();
		}
		
		function generateFunctions(){
				
			var link="/get_sessiondata";
			var sessionXML=loadXMLDoc(link);
			
			var currentrole;
			
			currentrole=sessionXML.getElementsByTagName("role")[0].childNodes[0].nodeValue;
			
			var newText="";
			
			if (currentrole=="Project Manager"){
				newText+='<input type="submit" value="Elimina"/>';
			}
			document.getElementById("functions").innerHTML=newText;
				
		}
		
		function loadOperatori(){
			
			var link="/sintesiTuttiUtenti";
			
			var operatoriXML=loadXMLDoc(link);
			
			var operatori=operatoriXML.getElementsByTagName("elemento");
			var i;
			var newText='<th><td class="listth">Username</td><td class="listth">Ruolo</td></th>';
			
			for(i=0;i<operatori.length;i++){
				username=operatoriXML.getElementsByTagName("username")[i].childNodes[0].nodeValue;
				role=operatoriXML.getElementsByTagName("role")[i].childNodes[0].nodeValue;
				
				newText+=('<tr><td><input type="radio" name="username" value="'+username+'"></td><td>'+username+'</td><td>'+role+'</td></tr>');
						 
			}
			var ulOperatori=document.getElementById("listatab");
			ulOperatori.innerHTML=newText;	
				
		}	
			
		
	</script>
	<link href="style/style.css" rel="stylesheet" type="text/css"/>
</head>

<body onload="init()">
	<div class = "header">

		<div class = "headerban">
			<h1><center> WEB ACTIVITY MANAGER </center></h1>
		</div>
		
		<div class = "session_data">
			<table>
				<tr>
					<td><b>Utente: </b></td>
					<td><div id = "current_user"></div>
					</td>
				</tr>
				<tr>
					<td>
						<b>Ruolo: </b></td>
					<td><div id = "current_role" ></div>
					</td>
				</tr>
				<tr>
					<td>
						<b>Progetto: </b></td>
					<td><div id = "current_project"></div>
					</td>
				</tr>
				<tr>
					<td>
						<a href="http://localhost:4444/logout"><input type="button" value="logout"/></a>
					</td>
				</tr>
			</table>
		</div>
	</div>
	
	<!-- MENU -->
	<div class = "menu">
		<ul id="menu">
		</ul>
	</div>
	
	<br>
	<br>
	
	<div class = "funct_name">
		<h2><center> Visualizza operatori di progetto </center></h2>
	</div>
	
	<!-- ELENCO DEGLIO OPERATORI, CON "RADIO" PER SELEZIONARLI -->
	<div class = "list">
		<form onSubmit="if(!confirm('Sei sicuro di voler eliminare questo operatore?')){return false;}" action="http://localhost:4444/deleteUtente">
			<fieldset>
				<legend> Lista operatori di progetto </legend>
				<table border="1" id = "listatab">
				</table>
				<br>
				<div id="functions"></div>
			</fieldset>
			
		</form>
	</div>
	
</body>

</html>